//----------------------------------------------------------------------------
// M A R I T I M E  R E S E A R C H  I N S T I T U T E  N E T H E R L A N D S
//----------------------------------------------------------------------------
// Copyright (C) 2009 - MARIN - All rights reserved - http://www.marin.nl
//----------------------------------------------------------------------------
// Program    : mermaid
// Module     : vbm
// File       : defines.h
//----------------------------------------------------------------------------

#ifndef DEFINES_H
#define DEFINES_H

//#define USEDOUBLE
#define USESHORT

#define CUDASOLVERNAME "cudarrb" // also used in "testserieel.pl"
//#define USE_CUDAWAVESCOMPUTER
//#define USE_CUDAINCOMINGWAVES

#ifdef USEDOUBLE
#define REAL double
#else
#define REAL float
#endif

#ifdef USESHORT
#define SHORT short
#else
#define SHORT int
#endif

// #define MAXWAVES true  // to limit wave heights and lows to depth 

// #define SMOOTHING // spatial smooting of pulses

#define MAXDEPTH true // for deterministic initialization (see IncomingWaves::startup)

// for use in Fredyn
//#define plaatjes
//#define PULSECORRECTION   // take wave height into account for pulse height calculation
#define PULSEACTIVE       // imprint pulse in waves
#define WAVECORRECTION    // correct waves inside ship to approximate sea level if PULSEACTIVE

#define FADEIN 30.0
#define SOLVER "rrb"
#define SPHERES           // red spheres for wave surface
// end use in Fredyn

//#define PRINT             // save fields in file

#define PI 3.14159265359

#define MST_VECTOR(a) (mst::Vector3d(a(0), a(1), a(2)))
#define MML_VECTOR(a) (mml::Vector3d(a(0), a(1), a(2)))

#define NRP 4 // number of pulses

#define SOLVEREDGE 3

#include <math.h>    // cos
#include <stdio.h>
#include <algorithm>

#include "Timer.h" // std::min

extern FILE *fp;

#ifdef _WINDOWS
#pragma warning(disable: 4305) // truncation from 'double' to 'float'
#endif
inline REAL pSlow(REAL currenttime, REAL fadein)
{
    return REAL(0.5 - 0.5 * cos(PI * std::min(1.0 * (currenttime / fadein), 1.0)));
}
inline REAL getGravity()
{
    return 9.81; // [m/s^2]  (in Benelux)
}
inline REAL getDensity()
{
    return 1025; // [kg/m^3] (at ?? Celsius)
}

/// deterministic or jonswap wave spectrum
enum WaveSpectrum
{
    undefWS, deterministicWS, jonswapWS
};

/// cosine hyperbolicus or parabolic variational model
enum VariationalModel
{
    undefVM, coshypVM, parabolicVM
};

/// initialization type: flat, file from previous run or wave spectrum
enum Initialization
{
    noInit, fileInit, spectrumInit
};

#ifdef _OPENMP
#include <omp.h>
/// returns number of seconds since program start
inline double seconds()
{
    return omp_get_wtime();
}
#else

static Timer timer;

/// returns number of seconds since program start
inline double seconds()
{
    return timer.getElapsedTime();
}
#endif

// debugging macros ------------------------------------------------------------

#define PrintArray1Dcontents(s,a,s1,e1); \
    { \
    std::string file = std::string(#a) + std::string(s) + ".txt"; \
    FILE *fp = fopen(file.c_str(), "w"); \
    for (int tmp1 = s1; tmp1 <= e1; ++tmp1) \
    { \
        fprintf(fp, "%G\n", a[tmp1]); \
    } \
    fclose(fp); \
    }

#define PrintArray2Dcontents(s,a,s1,e1,s2,e2); \
    { \
    std::string file = std::string(#a) + std::string(s) + ".txt"; \
    FILE *fp = fopen(file.c_str(), "w"); \
    for (int tmp2 = (int)s2; tmp2 <= (int)e2; ++tmp2) \
    { \
        for (int tmp1 = (int)s1; tmp1 <= (int)e1; ++tmp1) \
        { \
            fprintf(fp, "%G ", a[tmp1][tmp2]); \
        } \
        fprintf(fp, "\n"); \
    } \
    fclose(fp); \
    }

#define PrintArray2Dcontents1D(s,a,s1,e1,s2,e2); \
    { \
    std::string file = std::string(#a) + std::string(s) + ".txt"; \
    FILE *fp = fopen(file.c_str(), "w"); \
    for (int tmp1 = s1; tmp1 <= e1; ++tmp1) \
    { \
        for (int tmp2 = s2; tmp2 <= e2; ++tmp2) \
        { \
            fprintf(fp, "%d %d %G\n", tmp1, tmp2, a[tmp1][tmp2]); \
        } \
    } \
    fclose(fp); \
    }

#endif // DEFINES_H

